/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManageUE.java
 *
 * Created on 18 févr. 2011, 18:42:36
 */
package fr.GCAM.StudentManager.UI.GUI;

import fr.GCAM.StudentManager.Business.Facade.FacadeUE;
import fr.GCAM.StudentManager.Business.POJO.ECUE;
import fr.GCAM.StudentManager.Business.POJO.UE;
import fr.GCAM.StudentManager.UI.AbstractUIFactory;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Classe definissant la GUI de l'UE
 * @author pierre
 */
public class GUIUE extends GUI<UE> implements ActionListener {

    private FacadeUE fue;
    private String dao;

    /** Creates new form ManageUE */
    public GUIUE(String dao, String id) throws Exception {
        this.dao = dao;
        initComponents();
        fue = new FacadeUE(id, dao);

        libelle.setText("Libellé UE : " + fue.getLibelleUE());
        responsable.setText("Responsable : " + fue.getResponsable());
        ects.setText("ECTS : " + fue.getECTS());
        optionnel.setText("Optionnel : " + fue.getOptionnel());

        JPanel border, col1, col2;
        JButton detail;

        for (ECUE e : fue.getListeECUE()) {
            border = new JPanel();
            border.setLayout(new BoxLayout(border, BoxLayout.X_AXIS));
            border.setBorder(javax.swing.BorderFactory.createTitledBorder(e.getCodeMatiere()));

            col1 = new JPanel();
            col1.setLayout(new GridLayout(2, 1));
            col1.add(new JLabel("Libellé ECUE : " + e.getLibelleECUE()));
            col1.add(new JLabel("Responsable : " + e.getResponsable()));

            col2 = new JPanel();
            col2.setLayout(new FlowLayout(FlowLayout.RIGHT));
            detail = new JButton("Détails...");
            detail.putClientProperty("id", e.getCodeMatiere());
            detail.addActionListener(this);
            col2.add(detail);
            
            border.add(col1);
            border.add(col2);
            panelECUE.add(border);
        }

        listeEtudiantUE.setModel(new ApogeeTableModel(
                new String[]{"Nom", "Prenom", "Moyenne"},
                fue.getArrayOfEtudiantUE()));

        setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelUE = new javax.swing.JPanel();
        departement = new javax.swing.JLabel();
        fieldDepartement = new javax.swing.JTextField();
        etape = new javax.swing.JLabel();
        comboEtape = new javax.swing.JComboBox();
        semestre = new javax.swing.JLabel();
        comboSemestre = new javax.swing.JComboBox();
        ue = new javax.swing.JLabel();
        comboUE = new javax.swing.JComboBox();
        ects = new javax.swing.JLabel();
        responsable = new javax.swing.JLabel();
        libelle = new javax.swing.JLabel();
        panelListeEtudiantUE = new javax.swing.JScrollPane();
        listeEtudiantUE = new javax.swing.JTable();
        panelECUE = new javax.swing.JPanel();
        optionnel = new javax.swing.JLabel();
        jMenuBar = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenu3 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("GCAM StudentManager : UE");
        setResizable(false);

        departement.setText("Département : ");

        fieldDepartement.setEditable(false);
        fieldDepartement.setText("IG");
        fieldDepartement.setEnabled(false);
        fieldDepartement.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fieldDepartementActionPerformed(evt);
            }
        });

        etape.setText("Année");

        comboEtape.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "3", "4", "5" }));

        semestre.setText("Semestre : ");

        comboSemestre.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2" }));

        ue.setText("UE : ");

        comboUE.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "UE1", "UE2", "UE3", "UE4" }));

        ects.setText("ECTS : ");

        responsable.setText("Responsable :");

        libelle.setText("jLabel1");

        javax.swing.GroupLayout panelUELayout = new javax.swing.GroupLayout(panelUE);
        panelUE.setLayout(panelUELayout);
        panelUELayout.setHorizontalGroup(
            panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUELayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelUELayout.createSequentialGroup()
                        .addComponent(departement)
                        .addGap(18, 18, 18)
                        .addComponent(fieldDepartement, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(libelle))
                .addGap(18, 18, 18)
                .addGroup(panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelUELayout.createSequentialGroup()
                        .addComponent(etape)
                        .addGap(18, 18, 18)
                        .addComponent(comboEtape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(semestre)
                        .addGap(18, 18, 18)
                        .addComponent(comboSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(responsable))
                .addGap(18, 18, 18)
                .addGroup(panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelUELayout.createSequentialGroup()
                        .addComponent(ue)
                        .addGap(18, 18, 18)
                        .addComponent(comboUE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ects))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelUELayout.setVerticalGroup(
            panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUELayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(departement)
                    .addComponent(fieldDepartement, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(etape)
                    .addComponent(comboEtape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(semestre)
                    .addComponent(comboSemestre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ue)
                    .addComponent(comboUE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addGroup(panelUELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ects)
                    .addComponent(responsable)
                    .addComponent(libelle)))
        );

        listeEtudiantUE.setDragEnabled(true);
        listeEtudiantUE.setName("ListeEtudiants"); // NOI18N
        listeEtudiantUE.getTableHeader().setResizingAllowed(false);
        listeEtudiantUE.getTableHeader().setReorderingAllowed(false);
        panelListeEtudiantUE.setViewportView(listeEtudiantUE);

        panelECUE.setLayout(new java.awt.GridLayout(10, 1, 0, 5));

        optionnel.setText("Optionnel :");

        jMenu1.setText("Fichier");
        jMenuBar.add(jMenu1);

        jMenu2.setText("Edition");
        jMenuBar.add(jMenu2);

        jMenu3.setText("jMenu3");
        jMenuBar.add(jMenu3);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelListeEtudiantUE, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
                    .addComponent(panelUE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(optionnel)
                    .addComponent(panelECUE, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(77, 77, 77))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(panelUE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(optionnel))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(panelListeEtudiantUE)
                    .addComponent(panelECUE, javax.swing.GroupLayout.DEFAULT_SIZE, 601, Short.MAX_VALUE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void fieldDepartementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fieldDepartementActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_fieldDepartementActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboEtape;
    private javax.swing.JComboBox comboSemestre;
    private javax.swing.JComboBox comboUE;
    private javax.swing.JLabel departement;
    private javax.swing.JLabel ects;
    private javax.swing.JLabel etape;
    private javax.swing.JTextField fieldDepartement;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JLabel libelle;
    private javax.swing.JTable listeEtudiantUE;
    private javax.swing.JLabel optionnel;
    private javax.swing.JPanel panelECUE;
    private javax.swing.JScrollPane panelListeEtudiantUE;
    private javax.swing.JPanel panelUE;
    private javax.swing.JLabel responsable;
    private javax.swing.JLabel semestre;
    private javax.swing.JLabel ue;
    // End of variables declaration//GEN-END:variables

    public void actionPerformed(ActionEvent e) {
        try {
            AbstractUIFactory.getUIFactory("g").getUIECUE(dao, ((JComponent) e.getSource()).getClientProperty("id").toString());
        } catch (Exception ex) {
        }
    }
}
